﻿#region 引用

using System;
using System.Data.Entity;
using Sohobloo.SoMcCoffee.Data;

#endregion

namespace Mojito.Data.Initialization
{
    public static class DbInitializer
    {
        public enum DbInitializMode
        {
            Create,
            DropCreate,
            DropCreateOnChange,
            Migrate
        }


        #region 方法

        public static void Initialize(DbInitializMode mode = DbInitializMode.Migrate)
        {
            switch(mode)
            {
                case DbInitializMode.Create:
                    Database.SetInitializer(new CreateDatabaseIfNotExists<EfDbContext>());
                    break;
                case DbInitializMode.DropCreate:
                    Database.SetInitializer(new DropCreateDatabaseAlways<EfDbContext>());
                    break;
                case DbInitializMode.DropCreateOnChange:
                    Database.SetInitializer(new DropCreateDatabaseIfModelChanges<EfDbContext>()); 
                    break;
                case DbInitializMode.Migrate:
                    Database.SetInitializer(new MigrateDatabaseToLatestVersion<EfDbContext, Migrations.Configuration>());
                    break;
                default:
                    throw new ArgumentOutOfRangeException("mode");
            }
        }

        #endregion 方法
    }
}